package com.buba.service.impl;

import com.buba.pojo.Job;
import com.buba.pojo.Menu;
import com.buba.service.MenuService;
import com.buba.service.OrderMenuService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

@Service
@DubboService
public class OrderMenuServiceImpl implements OrderMenuService {
    @DubboReference
    private MenuService menuService;
    @Override
    public List<Menu> selMenu(Integer jobId) {
        return menuService.selMenu(jobId);
    }

    @Override
    public List<Menu> noDup(List<Job> jobList) {
        //使用set集合去重时 需要考虑是根据内容还是内存的虚地址去重
        //根据内容去重时 必须给对象重写equals() 方法 hashCode（）方法
        Set<Menu> menuSet = new TreeSet<>();
        for (Job job: jobList) {
            //遍历该职位拥有的菜单
            for (Menu menu:job.getMenuList()) {
                //把对象放入set集合中
                menuSet.add(menu);
            }
        }
        List<Menu> menuList= new ArrayList<>() ;
        for (Menu menu:menuSet) {
            menuList.add(menu);
        }
        return menuList;
    }

    @Override
    public List<Menu> selMenuAll() {
        return menuService.selMenuAll();
    }




}
